import java.util.ArrayList;

/**
 * Created by forcht on 2018/5/21.
 */
public class Solution {
    ArrayList<ArrayList<Integer>> list=new ArrayList<>();
    ArrayList<Integer> curList=new ArrayList<>();
    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        dfs(num);
        return list;
    }

    public void dfs(int[] num){
        if (curList.size()==num.length){
            list.add((ArrayList<Integer>) curList.clone());
            return;
        }
        for(int i=0;i<num.length;i++){
            if (!curList.contains(num[i])){
                curList.add(num[i]);
                dfs(num);
                curList.remove(curList.size()-1);
            }
        }
    }

    public static void main(String[] args) {
        Solution solution=new Solution();
        int[] a={1,2,4};
        System.out.println(solution.permute(a));
    }
}
